#ifndef SSL_CONFIG_H
#define SSL_CONFIG_H

#include <string>

#include "./SslTypes.h"

class SslConfig
{
public:
    SslConfig()
        : version_(SslVersion::Ssl12),
          cipherList_("HIGH:!aNULL:!MDS"),
          // OpenSSL格式的加密套件过滤串：
          // HIGH：只选用高强度加密算法（密钥长度>=128位）
          // !aNULL：禁用所有匿名身份验证的算法（强制要求服务器证书验证）
          // !MDS：禁用使用MD5散列的套件（MD5已被证明不安全）
          needVerifyClient_(false),
          verifyClientDepth_(4),
          sessionTimeout_(300),
          sessionCacheSize_(20480L)
    {
    }

    // 证书配置
    void setCertificateFile(const std::string &certFile)
    {
        this->certFile_ = certFile;
    }
    void setPrivateKeyFile(const std::string &privateKeyFile)
    {
        this->privateKeyFile_ = privateKeyFile;
    }
    void setCertificateChainFile(const std::string &certChainFile)
    {
        this->certChainFile_ = certChainFile;
    }

    std::string getCertificateFile() const
    {
        return this->certFile_;
    }
    std::string getPrivateKeyFile() const
    {
        return this->privateKeyFile_;
    }
    std::string getCertificateChainFile() const
    {
        return this->certChainFile_;
    }

    // 协议版本和加密套件配置
    void setProtocolVersion(SslVersion version)
    {
        this->version_ = version;
    }
    void setCipherList(const std::string &cipherList)
    {
        this->cipherList_ = cipherList;
    }

    SslVersion getProtocolVersion() const
    {
        return this->version_;
    }
    const std::string &getCipherList() const
    {
        return this->cipherList_;
    }

    // 客户端验证配置
    void setNeedVerifyClient(bool needVerifyClient)
    {
        needVerifyClient_ = needVerifyClient;
    }
    void setVerifyClientDepth(int verifyClientdepth)
    {
        this->verifyClientDepth_ = verifyClientdepth;
    }

    bool getNeedVerifyClient() const
    {
        return this->needVerifyClient_;
    }
    int getVerifyClientDepth() const
    {
        return this->verifyClientDepth_;
    }

    // 会话配置
    void setSessionTimeout(int seconds)
    {
        this->sessionTimeout_ = seconds;
    }
    void setSessionCacheSize(long size)
    {
        this->sessionCacheSize_ = size;
    }

    int getSessionTimeout() const
    {
        return this->sessionTimeout_;
    }
    long getSessionCacheSize() const
    {
        return this->sessionCacheSize_;
    }

private:
    // 证书配置
    std::string certFile_;       // 证书文件
    std::string privateKeyFile_; // 私钥文件
    std::string certChainFile_;  // 证书链文件
    // 协议版本和加密套件配置
    SslVersion version_;     // 协议版本
    std::string cipherList_; // 加密套件
    // 客户端验证配置
    bool needVerifyClient_; // 是否需要验证客户端
    int verifyClientDepth_; // 验证客户端深度
    // 会话配置
    int sessionTimeout_;    // 会话超时时间（秒）
    long sessionCacheSize_; // 会话缓存大小
};

#endif // SSL_CONFIG_H